<%var csstpl = {%>

<%};%>
<%var jstpl = {%>
<script>
    var app = new Vue({
        el: "#content",
        data: {
            query: {
                pageNumber: 1,
                pageSize: 10,
                name: '',
                phone: '',
                type:'',
            },
            data_result: {},
            agent: '',
            agentCity: '',
            state: false,
            levels: [],
            rechargeAgentCitys: [{}],
            item: {},
            rechargeAgent: {},
        },
        created: function() {
            this.loadPage("init")
            // 在这试试
            let form = layui.form;
            form.render();
        },
        mounted() {
            let form = layui.form;
            let laydate = layui.laydate;
            let that = this;
            form.on('radio(state)', function(data) {
                that.agentCity.status = data.value;
                that.$nextTick(function() {
                    form.render();
                })
            });

            form.on('radio(agentStatus)', function(data) {
                that.agentCity.agentStatus = data.value;
                that.$nextTick(function() {
                    form.render();
                })
            });


            form.on('submit(formDemo)', function(data) {
                alert("come in");
                let datas = data.field
                Ajax("/system/agent/audit", datas, function(res) {
                    if (res.state) {
                        gx.alert(res.msg);
                        that.loadPage("init");
                        form.render();
                        $("#auditModal").modal('hide');
                    } else {
                        gx.alert(res.msg);
                    }
                })
            });

            form.on('submit(rechargeSubmit)', function(data) {
                let datas = data.field
                Ajax("/system/agent/recharge", datas, function(res) {
                    if (res.state) {
                        gx.alert(res.msg);
                        that.loadPage("init");
                        form.render();
                        $("#rechargeModal").modal('hide');
                    } else {
                        gx.alert(res.msg);
                    }
                })
            });


            laydate.render({
                elem: '#downTimes',
                type: 'datetime',
                range: true,
                change: function(value, date, endDate) {
                },
                done: function(value, date, endDate) {
                }
            });

            form.on('submit(downLoadAgent)', function(data) {
                let datas = data.field

                location.href='/system/agent/downLoadAuditAgent?times='+datas.downTimes;
            });


        },
        methods: {
            loadPage: function(model) { //载入模式有两种  init初始化载入 load分页载入
                if (model == "init") {
                    this.query.pageNumber = 1;
                }
                Ajax("/system/agent/auditList", this.query, function(d) {
                    console.log(d);
                    app.data_result = d.list;
                    if (d.firstPage == true) {
                        layui.laypage.render({
                            elem: 'gexin_page' //注意，这里的 test1 是 ID，不用加 # 号
                            ,
                            layout: ['count', 'prev', 'page', 'next',
                                'limit', 'skip'
                            ],
                            count: d.totalRow //数据总数，从服务端得到
                            ,
                            limit: app.query.pageSize,
                            jump: function(obj, first) {
                                app.query.pageNumber = obj.curr;
                                if (app.query.pageSize != obj.limit) {
                                    app.query.pageSize = obj.limit;
                                    app.loadPage("init");
                                    return;
                                }
                                if (!first) {
                                    app.loadPage("load");
                                }
                            }
                        });
                    }
                })
            },
            audit: function(agent) {
                this.agentCity = agent;
                let form = layui.form;
                console.log(this.agentCity);
                this.$nextTick(function() {

                    form.render();
                    $("#auditModal").modal('show');
                })
            },
            recharge: function(agent) {
                let that = this;
                let form = layui.form;
                that.rechargeAgent = agent;
                Ajax('/system/agent/findAgentCity', {
                    id: agent.id
                }, function(res) {
                    that.rechargeAgentCitys = res;
                    that.$nextTick(function() {
                        form.render();
                        $("#rechargeModal").modal('show');
                    })
                })
            },
            open: function(d) {
                Vue.set(d, 'open', !d.open)
            },
            downLoad:function(){
                let form = layui.form;
                this.$nextTick(function() {
                    form.render();
                    $("#dowmLoadModal").modal('show');
                })
            }
        }
    })
</script>
<%};%>
<%layout("../layout/_layout_layui.html",{title:"代理商审核",jstpl:jstpl,csstpl:csstpl}){%>
<div class="layui-row" id="content" v-cloak>
    <div class="layui-col-md10">
        <div class="layui-form-item ">
            <div class="layui-input-inline">
                <input type="text" v-model="query.name" placeholder="输入代理商名称模糊查询" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <input type="text" v-model="query.phone" placeholder="输入联系电话模糊查询" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <select v-model="query.type" class="layui-input" lay-filter="selectProductId" placeholder="选择代理等级">
                    <option value=''>选择代理等级</option>
                    <option value='1'>普通代理商</option>
                    <option value='0'>区域代理商</option>
                    <option value='2'>二级代理商</option>
                    <option value='3'>特约代理商</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-col-md2">
        <div class="layui-form-item">
            <a @click="loadPage" class="layui-btn"><i class="layui-icon">&#xe615;</i> 查询/筛选</a>
            <a @click="downLoad" class="layui-btn"><i class="layui-icon">&#xe601;</i> 导出</a>
        </div>
    </div>
    <div class="layui-col-md12" style="margin-top: 20px">
        <table class="layui-table ">
            <thead>
            <tr>
                <th>ID              </th>
                <th>代理商名称      </th>
                <th>代理商电话      </th>
                <th>代理商地址      </th>
                <th>代理商老板名称  </th>
                <th>代理商门头照    </th>
                <th>代理商营业执照  </th>
                <th>代理区域        </th>
                <th>代理商类型      </th>
                <th>联系人      </th>
                <th>是否发送合同    </th>
                <th>保证金状态      </th>
                <th>压货金额状态    </th>
                <th>申请时间        </th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody v-for="d in data_result">
            <tr>
                <td>{{d.agentId}}</td>
                <td>{{d.agentName}}</td>
                <td>{{d.agent_phone}}</td>
                <td>{{d.address}}</td>
                <td>{{d.agent_boss_name}}</td>
                <td><img :src='d.logo_img'> </td>
                <td><img :src='d.business_license'> </td>
                <td>{{d.cityName}}<span v-if='d.areaName'> - {{d.areaName}}</span></td>
                <td>{{d.agentType==0?'区域代理商':d.agentType==1?'普通代理商':d.agentType==2?'二级代理商':d.agentType==3?'特约代理商':''}}</td>
                <td>{{d.agent_boss_name}}</td>
                <td>{{d.send_mail==1?'已发送':'未发送'}}</td>
                <td>{{d.cash_deposit_state==1?'已缴纳':'未缴纳'}}</td>
                <td>{{d.control_moeny_state==1?'已缴纳':'未缴纳'}}</td>
                <td>{{d.aduitTime}}</td>
                <td>
                    <a class="layui-btn layui-btn-sm" @click="audit(d)">审核</a>
                    <a :href="'javascript:gx.del(\'/system/agent/auditdelete/' +d.agentId+'\')'" class="layui-btn layui-btn-sm">删除</a>
                </td>
            </tr>

            </tbody>
            <tbody id="tbody_body" v-if="data_result.length==0">
            <tr>
                <td colspan="14" style="text-align:center;height:300px">
                    <h1>没有数据</h1>
                </td>
            </tr>
            </tbody>
        </table>
        <fieldset id="gexin_page" class="layui-elem-field layui-field-title"></fieldset>
    </div>




    <div class="modal fade" id="rechargeModal" tabindex="-1" role="dialog" aria-hidden="true">
        <form id="auditForm" class="layui-form form-horizontal ">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">
                            代理商充值
                        </h4>
                    </div>
                    <div class="modal-body">
                        <!-- 弹出框开始  -->
                        <div class="layui-row layui-col-space15">
                            <!-- 弹出框开始  -->
                            <input type="hidden" id="rechargeAgent.id" v-model="rechargeAgent.id" name="agentId">
                            <div class="layui-form-item">
                                <label class="layui-form-label">代理商</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" lay-verify="required" v-model="rechargeAgent.agent_name" readonly />
                                </div>
                            </div>
                            <div>
                                <label class="layui-form-label">充值区域</label>
                                <div class="layui-input-block">
                                    <select name="city_id">
                                        <option>选择充值的区域</option>
                                        <option :value="item.city_id" v-for="item in rechargeAgentCitys">{{item.cityName}}</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">充值金额</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" name="price" lay-verify="required|number" placeholder="请输入充值金额">
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" lay-submit lay-filter="rechargeSubmit">提交</button>
                                <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>




    <div class="modal fade" id="auditModal" tabindex="-1" role="dialog" aria-hidden="true">
        <form id="auditForm" class="layui-form form-horizontal ">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">
                            审核代理商
                        </h4>
                    </div>
                    <div class="modal-body">
                        <!-- 弹出框开始  -->
                        <div class="layui-row layui-col-space15">
                            <!-- 弹出框开始  -->
                            <input type="hidden" id="agentCity.agent_id" :value="agentCity.id" name="agentCity.id">
                            <input type="hidden" id="agentCity.agentType" :value="agentCity.agentType" name="agentType">
                            <input type="hidden" id="agentCity.agentId" :value="agentCity.agentId" name="agentId">
                            <input type="hidden" id="agentCity.level_id" :value="agentCity.level_id" name="level_id">
                            <input type="hidden" id="agentCity.city_id" :value="agentCity.city_id" name="city_id">
                            <input type="hidden" id="agentCity.area_id" :value="agentCity.area_id" name="area_id">
                            <div class="layui-form-item">
                                <label class="layui-form-label">代理商</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" lay-verify="required" v-model="agentCity.agentName" readonly placeholder="请输入资源的名称">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">代理商类型</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" lay-verify="required" :value="agentCity.agentType==0?'区域代理商':agentCity.agentType==1?'普通代理商':(agentCity.agentType==2&&agentCity.parent_id==null)?'二级代理商':agentCity.agentType==3?'特约代理商':''"
                                           readonly>
                                </div>
                            </div>
                            <div class="layui-form-item" v-if="agentCity.agentType==0">
                                <label class="layui-form-label">城市名称</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" lay-verify="required" v-model="agentCity.cityName" readonly placeholder="请输入资源的名称">
                                </div>
                            </div>
                            <div class="layui-form-item" v-if='agentCity.agentType==0&&agentCity.areaName'>
                                <label class="layui-form-label">区/县名称</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" lay-verify="required" v-model="agentCity.areaName" readonly placeholder="请输入资源的名称">
                                </div>
                            </div>

                            <div class="layui-form-item" v-show='agentCity.agentType==0'>
                                <label class="layui-form-label">审核状态</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="radio" lay-filter="state" title="通过" v-model="agentCity.status" value="1" name="agentCity.status">
                                    <input class="layui-input" type="radio" lay-filter="state" title="不通过" v-model="agentCity.status" value="0" name="agentCity.status">
                                </div>
                            </div>
                            <!-- 报错 -->
                            <div class="layui-form-item" v-show='agentCity.agentType!=0'>
                                <label class="layui-form-label">审核状态</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="radio" lay-filter="agentStatus" title="通过" v-model="agentCity.agentStatus" value="1" name="status">
                                    <input class="layui-input" type="radio" lay-filter="agentStatus" title="不通过" v-model="agentCity.agentStatus" value="0" name="status">
                                </div>
                            </div>

                            <div v-show="agentCity.status==1||agentCity.agentStatus==1">
                                <!-- <div class="layui-form-item" v-if='agentCity.agentType==0'>
                                    <label class="layui-form-label">缴纳保证金</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input" type="text" name="deposit" lay-verify="required|number" placeholder="请输入保证金">
                                    </div>
                                </div>
                                <div class="layui-form-item" v-if='agentCity.agentType==0'>
                                    <label class="layui-form-label">指定销售额</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input" type="text" name="sales" lay-verify="required|number" placeholder="请输入销售额">
                                    </div>
                                </div> -->

                                <!-- <div class="layui-form-item" v-if='agentCity.agentType==0'>
                                    <label class="layui-form-label">选择代理等级</label>
                                    <div class="layui-input-block">
                                        <select name="agentCity.level_id" lay-filter="level_id">
                                            <option value=''>请选择代理商级别</option>
                                            <%for(level in levelList){%>
                                                <option value='${level.id}'>${level.name}</option>
                                            <%}%>
                                        </select>
                                    </div>
                                </div> -->
                                <!--
                                                                                    <div class="layui-form-item" v-if='agentCity.agentType==1||agentCity.agentType==2'>
                                                                                        <label class="layui-form-label">选择代理等级</label>
                                                                                        <div class="layui-input-block">
                                                                                            <select name="level_id" lay-filter="level_id">
                                                                                                <option value=''>请选择代理商级别</option>
                                                                                                <%for(level in levelList){%>
                                                                                                    <option value='${level.id}'>${level.name}</option>
                                                                                                <%}%>
                                                                                            </select>
                                                                                        </div>
                                                                                    </div> -->

<!--                                <div class="layui-form-item" v-if='agentCity.agentType==3'>-->
<!--                                    <label class="layui-form-label">设置折扣</label>-->
<!--                                    <div class="layui-input-block">-->
<!--                                        <input class="layui-input" type="text" name="sales" lay-verify="required|number" placeholder="请输入折扣">-->
<!--                                    </div>-->
<!--                                </div>-->
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                                <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="modal fade" id="dowmLoadModal" tabindex="-1" role="dialog" aria-hidden="true">
    <form id="auditForm" class="layui-form form-horizontal ">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">
                        导出列表
                    </h4>
                </div>
                <div class="modal-body">
                    <!-- 弹出框开始  -->
                    <div class="layui-row layui-col-space15">
                        <!-- 弹出框开始  -->
                        <div class="layui-form-item">
                            <label class="layui-form-label">时间段</label>
                            <div class="layui-input-block">
                                <input class="layui-input" type="text" id='downTimes' name="downTimes" lay-verify="required" placeholder="选择导出时间段">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit lay-filter="downLoadAgent">提交</button>
                            <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<%};%>